<template>
  <div class="learning-history">
    <div class="history-header">
      <h3 class="history-title">{{ title }}</h3>
      <div class="history-filters">
        <select 
          v-model="selectedPeriod"
          class="period-select"
          @change="onPeriodChange"
          :disabled="isLoading"
        >
          <option value="week">近一周</option>
          <option value="month">近一月</option>
          <option value="quarter">近三月</option>
          <option value="year">近一年</option>
        </select>
        <button 
          v-if="showRefresh"
          class="refresh-btn"
          @click="refreshHistory"
          :disabled="isLoading"
        >
          <i class="icon-refresh" :class="{ 'rotating': isLoading }"></i>
        </button>
      </div>
    </div>
    
    <!-- 学习统计概览 -->
    <div class="history-overview" v-if="showOverview">
      <div class="overview-grid">
        <div class="overview-item">
          <div class="overview-icon">
            <i class="icon-words"></i>
          </div>
          <div class="overview-info">
            <div class="overview-value">{{ totalWordsLearned }}</div>
            <div class="overview-label">累计学习单词</div>
          </div>
        </div>
        <div class="overview-item">
          <div class="overview-icon">
            <i class="icon-time"></i>
          </div>
          <div class="overview-info">
            <div class="overview-value">{{ formatDuration(totalStudyTime) }}</div>
            <div class="overview-label">累计学习时长</div>
          </div>
        </div>
        <div class="overview-item">
          <div class="overview-icon">
            <i class="icon-streak"></i>
          </div>
          <div class="overview-info">
            <div class="overview-value">{{ currentStreak }}天</div>
            <div class="overview-label">当前连续学习</div>
          </div>
        </div>
        <div class="overview-item">
          <div class="overview-icon">
            <i class="icon-achievement"></i>
          </div>
          <div class="overview-info">
            <div class="overview-value">{{ achievements }}</div>
            <div class="overview-label">获得成就</div>
          </div>
        </div>
      </div>
    </div>
    
    <!-- 学习趋势图表 -->
    <div class="history-chart" v-if="showChart">
      <h4 class="chart-title">学习趋势</h4>
      <div class="chart-container">
        <div v-if="isLoading" class="chart-loading">
          <div class="loading-spinner"></div>
          <span>加载中...</span>
        </div>
        <div v-else class="chart-content">
          <!-- 简化的图表实现 -->
          <div class="chart-axis">
            <div class="chart-grid">
              <div 
                v-for="(day, index) in chartData"
                :key="day.date"
                class="chart-bar-container"
              >
                <div 
                  class="chart-bar"
                  :style="{ 
                    height: `${day.value * 100 / maxChartValue}%`,
                    backgroundColor: getBarColor(day.value)
                  }"
                  :title="`${day.date}: ${day.value}${chartUnit}`"
                ></div>
                <div class="chart-label">{{ formatChartLabel(day.date, index) }}</div>
              </div>
            </div>
            <div class="chart-y-axis">
              <div class="y-axis-label">{{ chartUnit }}</div>
              <div class="y-axis-ticks">
                <div v-for="tick in chartYAxisTicks" :key="tick" class="y-axis-tick">{{ tick }}</div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    
    <!-- 学习记录列表 -->
    <div class="history-list" v-if="showList">
      <h4 class="list-title">学习记录</h4>
      
      <div v-if="isLoading" class="list-loading">
        <div class="loading-spinner"></div>
        <span>加载中...</span>
      </div>
      
      <div v-else-if="records.length === 0" class="empty-records">
        <i class="icon-empty"></i>
        <p>暂无学习记录</p>
      </div>
      
      <div v-else class="records-container">
        <div 
          v-for="record in paginatedRecords"
          :key="record.id"
          class="record-item"
        >
          <div class="record-date">{{ formatRecordDate(record.date) }}</div>
          <div class="record-content">
            <div class="record-header">
              <div class="record-title">{{ record.title }}</div>
              <div class="record-duration">{{ formatDuration(record.duration) }}</div>
            </div>
            <div class="record-details">
              <span class="record-words">{{ record.words }} 单词</span>
              <span class="record-accuracy">{{ record.accuracy }}% 准确率</span>
              <span v-if="record.completed" class="record-status completed">已完成</span>
              <span v-else class="record-status incomplete">未完成</span>
            </div>
            <div v-if="record.note" class="record-note">
              <i class="icon-note"></i>
              {{ record.note }}
            </div>
          </div>
          <div class="record-actions">
            <button class="action-btn" @click="viewRecord(record.id)">
              <i class="icon-view"></i>
            </button>
          </div>
        </div>
        
        <!-- 分页 -->
        <div v-if="totalPages > 1" class="pagination">
          <button 
            class="page-btn"
            @click="currentPage = 1"
            :disabled="currentPage === 1"
          >
            首页
          </button>
          <button 
            class="page-btn"
            @click="currentPage--"
            :disabled="currentPage === 1"
          >
            上一页
          </button>
          <span class="page-info">
            {{ currentPage }} / {{ totalPages }}
          </span>
          <button 
            class="page-btn"
            @click="currentPage++"
            :disabled="currentPage === totalPages"
          >
            下一页
          </button>
          <button 
            class="page-btn"
            @click="currentPage = totalPages"
            :disabled="currentPage === totalPages"
          >
            末页
          </button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { ref, computed, watch, onMounted } from 'vue'
import { useProgressStore } from '@/store'
import { formatDuration, formatDate, formatRelativeDate } from '@/utils/formatUtils'
import { generateMockHistoryData } from '@/utils/mockData'

export default {
  name: 'LearningHistory',
  props: {
    title: {
      type: String,
      default: '学习历史'
    },
    showOverview: {
      type: Boolean,
      default: true
    },
    showChart: {
      type: Boolean,
      default: true
    },
    showList: {
      type: Boolean,
      default: true
    },
    showRefresh: {
      type: Boolean,
      default: true
    },
    recordsPerPage: {
      type: Number,
      default: 10
    },
    chartType: {
      type: String,
      default: 'words', // 'words' or 'time'
      validator: (value) => {
        return ['words', 'time'].includes(value)
      }
    },
    // 如果没有传入记录，则使用模拟数据
    records: {
      type: Array,
      default: null
    }
  },
  emits: ['refresh', 'view-record'],
  setup(props, { emit }) {
    const progressStore = useProgressStore()
    const isLoading = ref(false)
    const selectedPeriod = ref('week')
    const currentPage = ref(1)
    const localRecords = ref([])
    
    // 初始化数据
    onMounted(() => {
      loadHistoryData()
    })
    
    // 加载历史数据
    const loadHistoryData = async () => {
      isLoading.value = true
      try {
        // 如果props提供了records，则使用props的records
        if (props.records !== null) {
          localRecords.value = [...props.records]
        } else {
          // 否则生成模拟数据
          localRecords.value = generateMockHistoryData(selectedPeriod.value)
        }
        
        // 重置到第一页
        currentPage.value = 1
      } catch (error) {
        console.error('加载历史记录失败:', error)
      } finally {
        isLoading.value = false
      }
    }
    
    // 刷新历史数据
    const refreshHistory = () => {
      emit('refresh')
      loadHistoryData()
    }
    
    // 时间段变更
    const onPeriodChange = () => {
      loadHistoryData()
    }
    
    // 查看记录详情
    const viewRecord = (recordId) => {
      emit('view-record', recordId)
    }
    
    // 计算总页数
    const totalPages = computed(() => {
      return Math.ceil(localRecords.value.length / props.recordsPerPage)
    })
    
    // 计算分页后的记录
    const paginatedRecords = computed(() => {
      const startIndex = (currentPage.value - 1) * props.recordsPerPage
      const endIndex = startIndex + props.recordsPerPage
      return localRecords.value.slice(startIndex, endIndex)
    })
    
    // 计算统计数据
    const totalWordsLearned = computed(() => {
      return localRecords.value.reduce((sum, record) => sum + record.words, 0)
    })
    
    const totalStudyTime = computed(() => {
      return localRecords.value.reduce((sum, record) => sum + record.duration, 0)
    })
    
    // 假设从store获取连续学习天数和成就数
    const currentStreak = computed(() => {
      return progressStore.currentStreak || 7
    })
    
    const achievements = computed(() => {
      return progressStore.achievements || 3
    })
    
    // 生成图表数据
    const chartData = computed(() => {
      const days = []
      const now = new Date()
      let daysCount = 7 // 默认显示7天
      
      // 根据选择的时间段调整显示的天数
      switch (selectedPeriod.value) {
        case 'week':
          daysCount = 7
          break
        case 'month':
          daysCount = 30
          break
        case 'quarter':
          daysCount = 90
          break
        case 'year':
          daysCount = 365
          break
      }
      
      for (let i = daysCount - 1; i >= 0; i--) {
        const date = new Date(now)
        date.setDate(now.getDate() - i)
        const dateStr = date.toISOString().split('T')[0]
        
        // 查找当天的记录
        const dayRecords = localRecords.value.filter(record => 
          record.date.startsWith(dateStr)
        )
        
        // 计算当天的值
        let dayValue = 0
        if (props.chartType === 'words') {
          dayValue = dayRecords.reduce((sum, record) => sum + record.words, 0)
        } else {
          dayValue = Math.round(dayRecords.reduce((sum, record) => sum + record.duration, 0) / 60) // 转换为分钟
        }
        
        days.push({
          date: dateStr,
          value: dayValue
        })
      }
      
      return days
    })
    
    // 计算图表最大值
    const maxChartValue = computed(() => {
      const max = Math.max(...chartData.value.map(day => day.value), 1)
      return Math.ceil(max * 1.2) // 留出20%的空间
    })
    
    // 获取图表Y轴刻度
    const chartYAxisTicks = computed(() => {
      const max = maxChartValue.value
      const ticks = []
      const step = Math.ceil(max / 5)
      
      for (let i = 0; i <= 5; i++) {
        ticks.push(i * step)
      }
      
      return ticks
    })
    
    // 获取图表单位
    const chartUnit = computed(() => {
      return props.chartType === 'words' ? '单词' : '分钟'
    })
    
    // 获取柱状图颜色
    const getBarColor = (value) => {
      if (value === 0) return '#d9d9d9'
      if (value < 10) return '#ff4d4f'
      if (value < 30) return '#faad14'
      if (value < 50) return '#1890ff'
      return '#52c41a'
    }
    
    // 格式化图表标签
    const formatChartLabel = (dateStr, index) => {
      const date = new Date(dateStr)
      
      // 根据显示的天数决定标签格式
      if (chartData.value.length <= 7) {
        // 一周内显示星期
        return ['日', '一', '二', '三', '四', '五', '六'][date.getDay()]
      } else if (chartData.value.length <= 30) {
        // 一个月内显示日期
        return date.getDate().toString()
      } else {
        // 更长时间显示月份
        return `${date.getMonth() + 1}月`
      }
    }
    
    // 格式化记录日期
    const formatRecordDate = (dateStr) => {
      return formatRelativeDate(dateStr)
    }
    
    // 监听记录变化，重新计算分页
    watch(() => props.records, () => {
      if (props.records !== null) {
        localRecords.value = [...props.records]
        currentPage.value = 1
      }
    }, { deep: true })
    
    return {
      isLoading,
      selectedPeriod,
      currentPage,
      totalPages,
      paginatedRecords,
      totalWordsLearned,
      totalStudyTime,
      currentStreak,
      achievements,
      chartData,
      maxChartValue,
      chartYAxisTicks,
      chartUnit,
      formatDuration,
      formatDate,
      formatRecordDate,
      getBarColor,
      formatChartLabel,
      loadHistoryData,
      refreshHistory,
      onPeriodChange,
      viewRecord
    }
  }
}
</script>

<style scoped>
.learning-history {
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  padding: 20px;
  overflow: hidden;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid #f0f0f0;
}

.history-title {
  font-size: 18px;
  font-weight: 600;
  color: #262626;
  margin: 0;
}

.history-filters {
  display: flex;
  align-items: center;
  gap: 12px;
}

.period-select {
  padding: 6px 12px;
  border: 1px solid #d9d9d9;
  border-radius: 6px;
  font-size: 14px;
  color: #595959;
  background: #ffffff;
  cursor: pointer;
  transition: border-color 0.3s ease;
}

.period-select:focus {
  outline: none;
  border-color: #1890ff;
  box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2);
}

.period-select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.refresh-btn {
  width: 32px;
  height: 32px;
  border: 1px solid #d9d9d9;
  border-radius: 6px;
  background: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

.refresh-btn:hover:not(:disabled) {
  border-color: #1890ff;
  color: #1890ff;
}

.refresh-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.icon-refresh {
  display: inline-block;
  width: 16px;
  height: 16px;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M17.65 6.35C16.2 4.9 14.21 4 12 4c-4.42 0-7.99 3.58-7.99 8s3.57 8 7.99 8c3.73 0 6.84-2.55 7.73-6h-2.08c-.82 2.33-3.04 4-5.65 4-3.31 0-6-2.69-6-6s2.69-6 6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z"/></svg>');
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

.icon-refresh.rotating {
  animation: rotate 1s linear infinite;
}

@keyframes rotate {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* 学习统计概览 */
.history-overview {
  margin-bottom: 24px;
}

.overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.overview-item {
  background: #fafafa;
  border-radius: 8px;
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: all 0.3s ease;
}

.overview-item:hover {
  background: #e6f7ff;
  box-shadow: 0 2px 8px rgba(24, 144, 255, 0.1);
}

.overview-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
  flex-shrink: 0;
}

.icon-words,
.icon-time,
.icon-streak,
.icon-achievement {
  display: inline-block;
  width: 20px;
  height: 20px;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

.icon-words {
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%231890ff"><path d="M9.4 16.6L4.8 12l4.6-4.6L8 6l-6 6 6 6 1.4-1.4zm5.2 0l4.6-4.6-4.6-4.6L16 6l6 6-6 6-1.4-1.4z"/></svg>');
}

.icon-time {
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%2352c41a"><path d="M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zm6.93 6h-2.95c-.32-1.25-.78-2.45-1.38-3.56 1.84.63 3.37 1.91 4.33 3.56zM12 4.04c.83 1.2 1.48 2.53 1.91 3.96h-3.82c.43-1.43 1.08-2.76 1.91-3.96zM4.26 14C4.1 13.36 4 12.69 4 12s.1-1.36.26-2h3.38c-.08.66-.14 1.32-.14 2 0 .68.06 1.34.14 2H4.26zm.82 2h2.95c.32 1.25.78 2.45 1.38 3.56-1.84-.63-3.37-1.9-4.33-3.56zm2.95-8H5.08c.96-1.66 2.49-2.93 4.33-3.56C8.81 5.55 8.35 6.75 8.03 8zM12 19.96c-.83-1.2-1.48-2.53-1.91-3.96h3.82c-.43 1.43-1.08 2.76-1.91 3.96zM14.34 14H9.66c-.09-.66-.16-1.32-.16-2 0-.68.07-1.35.16-2h4.68c.09.65.16 1.32.16 2 0 .68-.07 1.34-.16 2zm.25 5.56c.6-1.11 1.06-2.31 1.38-3.56h2.95c-.96 1.65-2.49 2.93-4.33 3.56zM16.36 14c.08-.66.14-1.32.14-2 0-.68-.06-1.34-.14-2h3.38c.16.64.26 1.31.26 2s-.1 1.36-.26 2h-3.38z"/></svg>');
}

.icon-streak {
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23faad14"><path d="M12 7V3H2v18h20V7H12zM6 19H4v-2h2v2zm0-4H4v-2h2v2zm0-4H4V9h2v2zm0-4H4V5h2v2zm4 12H8v-2h2v2zm0-4H8v-2h2v2zm0-4H8V9h2v2zm0-4H8V5h2v2zm10 12h-8v-2h2v-2h-2v-2h2v-2h-2V9h8v10zm-2-8h-2v2h2v-2zm0 4h-2v2h2v-2z"/></svg>');
}

.icon-achievement {
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%239254de"><path d="M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-7 14h-2v-4H8v-2h2V9h2v2h2v2h-2v4zm4-8h-2V7h2v2z"/></svg>');
}

.overview-info {
  flex: 1;
}

.overview-value {
  font-size: 20px;
  font-weight: bold;
  color: #262626;
  margin-bottom: 4px;
}

.overview-label {
  font-size: 13px;
  color: #8c8c8c;
}

/* 学习趋势图表 */
.history-chart {
  margin-bottom: 24px;
}

.chart-title {
  font-size: 16px;
  font-weight: 600;
  color: #262626;
  margin: 0 0 16px 0;
}

.chart-container {
  background: #fafafa;
  border-radius: 8px;
  padding: 20px;
  min-height: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chart-loading {
  text-align: center;
  color: #8c8c8c;
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #f0f0f0;
  border-top-color: #1890ff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 8px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.chart-content {
  width: 100%;
}

.chart-axis {
  position: relative;
  height: 200px;
}

.chart-grid {
  display: flex;
  align-items: flex-end;
  height: 100%;
  gap: 8px;
  padding-bottom: 20px;
}

.chart-bar-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  min-height: 100%;
}

.chart-bar {
  width: 60%;
  background: #1890ff;
  border-radius: 4px 4px 0 0;
  transition: all 0.3s ease;
  cursor: pointer;
}

.chart-bar:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.chart-label {
  position: absolute;
  bottom: 0;
  font-size: 11px;
  color: #8c8c8c;
  text-align: center;
  white-space: nowrap;
}

.chart-y-axis {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 40px;
}

.y-axis-label {
  position: absolute;
  top: 0;
  left: 0;
  font-size: 12px;
  color: #8c8c8c;
}

.y-axis-ticks {
  position: absolute;
  right: 0;
  top: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.y-axis-tick {
  font-size: 10px;
  color: #8c8c8c;
  text-align: right;
}

/* 学习记录列表 */
.history-list {
  margin-bottom: 8px;
}

.list-title {
  font-size: 16px;
  font-weight: 600;
  color: #262626;
  margin: 0 0 16px 0;
}

.list-loading {
  text-align: center;
  padding: 40px 20px;
  color: #8c8c8c;
}

.empty-records {
  text-align: center;
  padding: 40px 20px;
}

.icon-empty {
  display: inline-block;
  width: 64px;
  height: 64px;
  margin-bottom: 16px;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23d9d9d9"><path d="M20 6h-3V4c0-1.11-.89-2-2-2H9c-1.11 0-2 .89-2 2v2H4c-1.11 0-2 .89-2 2v11c0 1.11.89 2 2 2h16c1.11 0 2-.89 2-2V8c0-1.11-.89-2-2-2zM9 4h6v2H9V4zm11 15H4v-2h16v2zm0-5H4V8h3v2h2V8h6v2h2V8h3v2z"/></svg>');
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

.empty-records p {
  font-size: 16px;
  color: #8c8c8c;
  margin: 0;
}

.records-container {
  max-height: 400px;
  overflow-y: auto;
}

.record-item {
  background: #fafafa;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 12px;
  transition: all 0.3s ease;
}

.record-item:hover {
  background: #e6f7ff;
  box-shadow: 0 2px 8px rgba(24, 144, 255, 0.1);
}

.record-date {
  font-size: 12px;
  color: #1890ff;
  margin-bottom: 8px;
}

.record-content {
  flex: 1;
}

.record-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.record-title {
  font-size: 14px;
  font-weight: 600;
  color: #262626;
}

.record-duration {
  font-size: 12px;
  color: #8c8c8c;
}

.record-details {
  display: flex;
  gap: 16px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.record-words,
.record-accuracy {
  font-size: 12px;
  color: #8c8c8c;
}

.record-status {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 12px;
  font-weight: 500;
}

.record-status.completed {
  background: #f6ffed;
  color: #52c41a;
}

.record-status.incomplete {
  background: #fff1f0;
  color: #ff4d4f;
}

.record-note {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #8c8c8c;
  padding-top: 8px;
  border-top: 1px solid #f0f0f0;
}

.icon-note {
  display: inline-block;
  width: 14px;
  height: 14px;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%238c8c8c"><path d="M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V8l-6-6zm2 16H8v-2h8v2zm0-4H8v-2h8v2zm-3-5V3.5L18.5 9H13z"/></svg>');
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

.record-actions {
  display: flex;
  align-items: flex-start;
}

.action-btn {
  width: 32px;
  height: 32px;
  border: 1px solid #d9d9d9;
  border-radius: 6px;
  background: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

.action-btn:hover {
  border-color: #1890ff;
  color: #1890ff;
}

.icon-view {
  display: inline-block;
  width: 16px;
  height: 16px;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5zM12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z"/></svg>');
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

/* 分页 */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid #f0f0f0;
}

.page-btn {
  padding: 6px 12px;
  border: 1px solid #d9d9d9;
  border-radius: 6px;
  background: #ffffff;
  font-size: 14px;
  color: #595959;
  cursor: pointer;
  transition: all 0.3s ease;
}

.page-btn:hover:not(:disabled) {
  border-color: #1890ff;
  color: #1890ff;
}

.page-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.page-info {
  font-size: 14px;
  color: #8c8c8c;
  min-width: 80px;
  text-align: center;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .learning-history {
    padding: 16px;
  }
  
  .overview-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .chart-container {
    padding: 16px;
  }
  
  .chart-grid {
    gap: 4px;
  }
  
  .chart-label {
    font-size: 10px;
  }
  
  .record-details {
    gap: 12px;
  }
}

@media (max-width: 480px) {
  .history-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  
  .history-filters {
    width: 100%;
    justify-content: space-between;
  }
  
  .overview-grid {
    grid-template-columns: 1fr;
  }
  
  .chart-y-axis {
    display: none;
  }
  
  .chart-bar {
    width: 80%;
  }
  
  .pagination {
    flex-wrap: wrap;
  }
  
  .page-btn {
    padding: 4px 8px;
    font-size: 12px;
  }
}

/* 滚动条样式 */
.records-container::-webkit-scrollbar {
  width: 6px;
}

.records-container::-webkit-scrollbar-track {
  background: #f0f0f0;
  border-radius: 3px;
}

.records-container::-webkit-scrollbar-thumb {
  background: #d9d9d9;
  border-radius: 3px;
}

.records-container::-webkit-scrollbar-thumb:hover {
  background: #bfbfbf;
}
</style>